﻿using Blog.Core.Common;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MyApp.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace MyApp.WebApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RedisController : ControllerBase
    {
        private IRedisCacheManager RedisCacheManager;
       
        public RedisController(IRedisCacheManager RedisCacheManager)
        {
            this.RedisCacheManager = RedisCacheManager;
           
        }
        /// <summary>
        /// 查询Redis值
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpGet]
        public string GetValue(string key)
        {
       
            return RedisCacheManager.GetValue(key);
        }
        /// <summary>
        /// 添加Redis键值对
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        [HttpPost]
        public void SetValue(string key,string value)
        {
            RedisCacheManager.Set(key, value, TimeSpan.FromMinutes(10));
        }
    }
}
